package cn.edu.tsinghua.sthuapp;


import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.lang.String;

class EventTypeAdapter extends BaseAdapter{
	int allDraw[]=Constant.TYPE_DRAW;
	String allText[]=Constant.TYPE_TEXT;
	int chooseDraw=R.drawable.choose;
	int choosePosition=0;
	private Context context;
	public EventTypeAdapter(Activity a,int choose){
		context=a;
		choosePosition=choose;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return allText.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater li=LayoutInflater.from(context);
		convertView=li.inflate(R.layout.eventtypeitem, null);
		if(convertView!=null){
			convertView.setTag(new Integer(position));
			ImageView typeImg=(ImageView)convertView.findViewById(R.id.eventtypeimg);
			typeImg.setImageResource(allDraw[position]);
			TextView textView=(TextView)convertView.findViewById(R.id.eventtypetext);
			textView.setText(allText[position]);
			if(position==choosePosition){
				ImageView chooseImg=(ImageView)convertView.findViewById(R.id.eventtypechoose);
				chooseImg.setImageResource(chooseDraw);
			}else{
				ImageView img=(ImageView)convertView.findViewById(R.id.eventtypechoose);
				img.setImageResource(R.drawable.nothing);
			}
		}
		return convertView;
	}
	public void reChoose(int p){
		choosePosition=p;
		this.notifyDataSetChanged();
	}
	
	
}
public class EventTypeActivity extends Activity{
	ListView lv=null;
	int choosePosition=0;
	public void doBack(View view){
		this.finish();
		overridePendingTransition(R.anim.hold, R.anim.unfade);
	}
	public void chooseBack(View view){
		ImageView imageView=(ImageView)view.findViewById(R.id.eventtypechoose);
		int position=(Integer)view.getTag();
		EventTypeAdapter myAdapter=(EventTypeAdapter)lv.getAdapter();
		myAdapter.reChoose(position);
		Intent intent=new Intent();
		intent.putExtra("type",position);
		setResult(23432,intent);
		finish();
		overridePendingTransition(R.anim.hold, R.anim.unfade);
	}
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eventtype);
        Intent intent=getIntent();
        choosePosition=intent.getIntExtra("type", 0);       
        Button button = (Button)(findViewById(R.id.typenewsbtn));
		button.setText(Constant.TYPE_TEXT[choosePosition]);
        lv=(ListView)findViewById(R.id.typelist);
		EventTypeAdapter adapter=new EventTypeAdapter(this,choosePosition);
		lv.setAdapter(adapter); 
    }
}

